<?php
/**
 * Created by DocController.class.php.
 * User: tqj
 * Date: 2017-05-27
 * Time: 14:34
 */

namespace Admin\Controller;
use Think\Controller;

class DocController extends CommonController
{
    public function addDoc()
    {
        if(IS_POST) {
            $post=I('post.');
            $Model =D('Doc');
            $result = $Model->saveData($post ,$_FILES['file']);
            //dump($data);die();
            if($result){
                $this->success('添加成功',U('showList'),3);
            }else{
                $this->error('fail');
            }
        } else {
            $this->display();
        }
    }

    public  function  showList()
    {
        $model = D('Doc');
        $data = $model->select();
        $this->assign('list', $data);
        $this->display();
    }

    public  function download(){
        $id = I('get.id');
        $data=M('Doc')->find($id);
        $file=WORKING_PATH.$data['file_path'];

        header('Content-type:application/octet-stream');
        header('Content-Disposition:attachment;filename="'.basename($file).'"');
        header('Content-Length:'.filesize($file));
        readfile($file);
    }
    public  function showContent(){
        $id=I('get.id');
        $data=M('Doc')->find($id);
        $data=htmlspecialchars_decode($data['content']);
        echo $data;
    }
    public  function edit (){
        if(IS_POST){
            $post=I('post.');
            $result=D('Doc')->updateDoc($post,$_FILES['file']);
            if($result){
                $this->success('修改成功',U('showList'),3);
            }else{
                $this->error('失败，重修修改');
            }
        }else{
            $id=I('get.id');
            $data=M("Doc")->find($id);
            $this->assign('data',$data);
            $this->display();
        }
    }
}